<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

<title>class CzController - Rails Application Documentation</title>

<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
</script>

<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="./index.html">Home</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>app/controllers/cz_controller.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link"><a href="ApplicationController.html">ApplicationController</a>
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-analyze">#analyze</a>
    
    <li><a href="#method-i-insert_controlfield">#insert_controlfield</a>
    
    <li><a href="#method-i-insert_datafield">#insert_datafield</a>
    
    <li><a href="#method-i-insert_subfield">#insert_subfield</a>
    
    <li><a href="#method-i-oconvert">#oconvert</a>
    
    <li><a href="#method-i-ooldconvert">#ooldconvert</a>
    
    <li><a href="#method-i-showsubfield">#showsubfield</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="./doc/README_FOR_APP.html">README_FOR_APP</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="./MarcTools.html">MarcTools</a>
  
    <li><a href="./MarcTools/MarcConverter.html">MarcTools::MarcConverter</a>
  
    <li><a href="./ApplicationController.html">ApplicationController</a>
  
    <li><a href="./ApplicationHelper.html">ApplicationHelper</a>
  
    <li><a href="./CzController.html">CzController</a>
  
    <li><a href="./MarcconverterController.html">MarcconverterController</a>
  
    <li><a href="./Object.html">Object</a>
  
    <li><a href="./OracleController.html">OracleController</a>
  
    <li><a href="./PersonController.html">PersonController</a>
  
    <li><a href="./PersonHelper.html">PersonHelper</a>
  
    <li><a href="./RsqvHelper.html">RsqvHelper</a>
  
    <li><a href="./RsqvpreviewController.html">RsqvpreviewController</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class CzController</h1>

  <div id="description" class="description">
    
  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-analyze" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">analyze</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="analyze-source">
            <pre><span class="ruby-comment"># File app/controllers/cz_controller.rb, line 26</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">analyze</span>
  <span class="ruby-identifier">require</span> <span class="ruby-string">'libxml'</span>
  <span class="ruby-identifier">dn</span> =<span class="ruby-string">'dn:http://www.loc.gov/MARC21/slim'</span>
  <span class="ruby-identifier">xml_document</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">file</span>(<span class="ruby-string">'/home/stephan/RSQV/cz.xml'</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-string">&quot;extext&quot;</span>]
    <span class="ruby-identifier">rismid</span>=<span class="ruby-identifier">params</span>[<span class="ruby-string">&quot;extext&quot;</span>][<span class="ruby-string">&quot;name&quot;</span>]
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">book_xpath</span> = <span class="ruby-string">'//dn:record'</span>
  <span class="ruby-identifier">nodes</span>=<span class="ruby-identifier">xml_document</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">book_xpath</span>,<span class="ruby-identifier">dn</span>)
  <span class="ruby-ivar">@countnodes</span>=<span class="ruby-identifier">nodes</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-ivar">@res</span>={}
  <span class="ruby-identifier">nodes</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">record</span><span class="ruby-operator">|</span> <span class="ruby-identifier">record</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">node</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">att</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">tag</span>=<span class="ruby-identifier">node</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">att</span>.<span class="ruby-identifier">name</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">att</span>.<span class="ruby-identifier">name</span><span class="ruby-operator">==</span><span class="ruby-string">&quot;tag&quot;</span>
        <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@res</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">tag</span>)
          <span class="ruby-ivar">@res</span>[<span class="ruby-identifier">tag</span>]=[]
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">node</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">subf</span><span class="ruby-operator">|</span>
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">subf</span>.<span class="ruby-identifier">name</span><span class="ruby-operator">==</span><span class="ruby-string">&quot;subfield&quot;</span>
            <span class="ruby-identifier">subf</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each</span> {
              <span class="ruby-operator">|</span><span class="ruby-identifier">atts</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@res</span>[<span class="ruby-identifier">tag</span>] <span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">subf</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">atts</span>.<span class="ruby-identifier">name</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">atts</span>.<span class="ruby-identifier">name</span><span class="ruby-operator">==</span><span class="ruby-string">&quot;code&quot;</span> <span class="ruby-keyword">and</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@res</span>[<span class="ruby-identifier">tag</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">subf</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">atts</span>.<span class="ruby-identifier">name</span>])
            }
          <span class="ruby-keyword">end</span>
        }
      }
    }
  }
  <span class="ruby-ivar">@endlist</span>=[]
  <span class="ruby-ivar">@res</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@endlist</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">k</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">k</span>}
  <span class="ruby-ivar">@el</span>=<span class="ruby-ivar">@endlist</span>.<span class="ruby-identifier">sort</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- analyze-source -->
          
        </div>

        

        
      </div><!-- analyze-method -->

    
      <div id="method-i-insert_controlfield" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">insert_controlfield</span><span
            class="method-args">(node, tag, term)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="insert_controlfield-source">
            <pre><span class="ruby-comment"># File app/controllers/cz_controller.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">insert_controlfield</span>(<span class="ruby-identifier">node</span>, <span class="ruby-identifier">tag</span>, <span class="ruby-identifier">term</span>)
  <span class="ruby-identifier">node</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">controlfield</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;controlfield&quot;</span>)
  <span class="ruby-identifier">controlfield</span>[<span class="ruby-string">'tag'</span>]=<span class="ruby-identifier">tag</span>
  <span class="ruby-identifier">controlfield</span>.<span class="ruby-identifier">content</span>=<span class="ruby-identifier">term</span>
  <span class="ruby-identifier">controlfield</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- insert_controlfield-source -->
          
        </div>

        

        
      </div><!-- insert_controlfield-method -->

    
      <div id="method-i-insert_datafield" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">insert_datafield</span><span
            class="method-args">(node, tag)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="insert_datafield-source">
            <pre><span class="ruby-comment"># File app/controllers/cz_controller.rb, line 4</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">insert_datafield</span>(<span class="ruby-identifier">node</span>, <span class="ruby-identifier">tag</span>)
  <span class="ruby-identifier">node</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">datafield</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;datafield&quot;</span>)
  <span class="ruby-identifier">datafield</span>[<span class="ruby-string">'tag'</span>]=<span class="ruby-identifier">tag</span>
  <span class="ruby-identifier">datafield</span>[<span class="ruby-string">'ind1'</span>]=<span class="ruby-string">&quot; &quot;</span>
  <span class="ruby-identifier">datafield</span>[<span class="ruby-string">'ind2'</span>]=<span class="ruby-string">&quot; &quot;</span>
  <span class="ruby-identifier">datafield</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- insert_datafield-source -->
          
        </div>

        

        
      </div><!-- insert_datafield-method -->

    
      <div id="method-i-insert_subfield" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">insert_subfield</span><span
            class="method-args">(node, code, term)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="insert_subfield-source">
            <pre><span class="ruby-comment"># File app/controllers/cz_controller.rb, line 12</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">insert_subfield</span>(<span class="ruby-identifier">node</span>, <span class="ruby-identifier">code</span>, <span class="ruby-identifier">term</span>)
  <span class="ruby-identifier">node</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">subfield</span> =<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span> <span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;subfield&quot;</span>)
  <span class="ruby-identifier">subfield</span>[<span class="ruby-string">'code'</span>]=<span class="ruby-identifier">code</span>
  <span class="ruby-identifier">subfield</span>.<span class="ruby-identifier">content</span>=<span class="ruby-identifier">term</span>
  <span class="ruby-identifier">subfield</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- insert_subfield-source -->
          
        </div>

        

        
      </div><!-- insert_subfield-method -->

    
      <div id="method-i-oconvert" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">oconvert</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="oconvert-source">
            <pre><span class="ruby-comment"># File app/controllers/cz_controller.rb, line 75</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">oconvert</span>
    <span class="ruby-identifier">require</span> <span class="ruby-string">'MarcTools'</span>
    <span class="ruby-identifier">dn</span> =<span class="ruby-string">'dn:http://www.loc.gov/MARC21/slim'</span>
    <span class="ruby-identifier">xml_document</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">file</span>(<span class="ruby-string">'/home/stephan/RSQV/cz.xml'</span>)
    <span class="ruby-identifier">book_xpath</span> = <span class="ruby-string">'//dn:record'</span>
    <span class="ruby-ivar">@old_xml</span>=<span class="ruby-identifier">xml_document</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">book_xpath</span>,<span class="ruby-identifier">dn</span>)[<span class="ruby-value">12</span>]

    <span class="ruby-identifier">converter</span>=<span class="ruby-constant">MarcTools</span><span class="ruby-operator">::</span><span class="ruby-constant">MarcConverter</span>.<span class="ruby-identifier">new</span>
    <span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">marc_to_hash</span>(<span class="ruby-ivar">@old_xml</span>)
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">updateElements</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'031$a'</span>, <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]})
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">updateElements</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'031$b'</span>, <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]})
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">updateElements</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'031$c'</span>, <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]})
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">updateElements</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'100$a'</span>, <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>  <span class="ruby-identifier">a</span>[<span class="ruby-value">-1</span>]<span class="ruby-operator">==</span><span class="ruby-string">','</span> <span class="ruby-operator">?</span>   <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>] <span class="ruby-operator">:</span>  <span class="ruby-identifier">a</span>})
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">updateElements</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'700$a'</span>, <span class="ruby-identifier">lambda</span>  { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>  <span class="ruby-identifier">a</span>[<span class="ruby-value">-1</span>]<span class="ruby-operator">==</span><span class="ruby-string">','</span> <span class="ruby-operator">?</span>   <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>] <span class="ruby-operator">:</span>  <span class="ruby-identifier">a</span>})
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">updateElements</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'240$a'</span>, <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>  <span class="ruby-identifier">a</span>[<span class="ruby-value">-1</span>]<span class="ruby-operator">==</span><span class="ruby-string">','</span> <span class="ruby-operator">?</span>   <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>] <span class="ruby-operator">:</span>  <span class="ruby-identifier">a</span>})
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">changeTag</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'246'</span>, <span class="ruby-string">'730'</span>) 
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">changeTag</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'080'</span>, <span class="ruby-string">'500'</span>)
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">changeTag</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'910'</span>, <span class="ruby-string">'852'</span>)
<span class="ruby-ivar">@marc_hash</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">insertTag</span>(<span class="ruby-ivar">@marc_hash</span>,<span class="ruby-string">'852$a'</span>, <span class="ruby-string">'CZ-Bu'</span>)

    <span class="ruby-ivar">@new_xml</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">hash_to_marc</span>(<span class="ruby-ivar">@marc_hash</span>)
  <span class="ruby-keyword">end</span></pre>
          </div><!-- oconvert-source -->
          
        </div>

        

        
      </div><!-- oconvert-method -->

    
      <div id="method-i-ooldconvert" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">ooldconvert</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="ooldconvert-source">
            <pre><span class="ruby-comment"># File app/controllers/cz_controller.rb, line 98</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">ooldconvert</span>
    <span class="ruby-identifier">require</span> <span class="ruby-string">'MarcConverter'</span>
    <span class="ruby-identifier">dn</span> =<span class="ruby-string">'dn:http://www.loc.gov/MARC21/slim'</span>
    <span class="ruby-identifier">xml_document</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">file</span>(<span class="ruby-string">'/home/stephan/RSQV/cz.xml'</span>)
    <span class="ruby-identifier">book_xpath</span> = <span class="ruby-string">'//dn:record'</span>
    <span class="ruby-ivar">@doc1</span>=<span class="ruby-identifier">xml_document</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">book_xpath</span>,<span class="ruby-identifier">dn</span>)[<span class="ruby-value">0</span>]
    <span class="ruby-comment">#a=%w[ leader 001 003 005 007 008 031$a 031$b 031$c 100$a 100$d 240$a 245$a ]</span>
    <span class="ruby-comment">#a=%w[ 031$a 031$b 031$c 100$a  240$a]</span>
    <span class="ruby-identifier">a</span>=<span class="ruby-node">%w[ 100$a  240$a]</span>
    <span class="ruby-identifier">converter</span>=<span class="ruby-constant">MarcConverter</span><span class="ruby-operator">::</span><span class="ruby-constant">MarcCollection</span>.<span class="ruby-identifier">new</span>
    <span class="ruby-identifier">converter</span>.<span class="ruby-identifier">taglist</span>=<span class="ruby-identifier">a</span>
    <span class="ruby-identifier">converter</span>.<span class="ruby-identifier">taglist</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">converter</span>.<span class="ruby-identifier">insertMarcElement</span>(<span class="ruby-ivar">@doc1</span>,<span class="ruby-identifier">e</span>)}
    <span class="ruby-ivar">@rec</span>=<span class="ruby-identifier">converter</span>.<span class="ruby-identifier">result</span>
    <span class="ruby-comment">#@build=MarcConverter::MarcBuilder.new(LibXML::XML::Document.new())</span>

    <span class="ruby-ivar">@dub</span>=<span class="ruby-ivar">@rec</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)<span class="ruby-operator">+</span><span class="ruby-identifier">e</span>.<span class="ruby-identifier">position</span>.<span class="ruby-identifier">to_s</span>}.<span class="ruby-identifier">uniq</span>
    <span class="ruby-ivar">@sort</span>=<span class="ruby-ivar">@rec</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)<span class="ruby-operator">+</span><span class="ruby-identifier">e</span>.<span class="ruby-identifier">position</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>,<span class="ruby-string">&quot;&quot;</span>)<span class="ruby-operator">+</span><span class="ruby-identifier">e</span>.<span class="ruby-identifier">content</span>]}

    <span class="ruby-ivar">@doc</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>()
    <span class="ruby-ivar">@doc</span>.<span class="ruby-identifier">root</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;collection&quot;</span>)
    <span class="ruby-ivar">@doc</span>.<span class="ruby-identifier">root</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@record</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;record&quot;</span>)

    <span class="ruby-ivar">@dub</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>]<span class="ruby-operator">==</span><span class="ruby-string">'00'</span>
        <span class="ruby-ivar">@record</span> <span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">controlfield</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;controlfield&quot;</span>)
        <span class="ruby-identifier">controlfield</span>[<span class="ruby-string">'tag'</span>]=<span class="ruby-identifier">e</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]

      <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">e</span><span class="ruby-operator">==</span><span class="ruby-string">'leader1'</span>
        <span class="ruby-ivar">@record</span> <span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">leader</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;leader&quot;</span>)
        <span class="ruby-identifier">leader</span>.<span class="ruby-identifier">content</span>=<span class="ruby-identifier">e</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]
      <span class="ruby-keyword">else</span>
        <span class="ruby-ivar">@record</span> <span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">datafield</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;datafield&quot;</span>)
        <span class="ruby-identifier">marker</span>=<span class="ruby-identifier">e</span>
        <span class="ruby-identifier">datafield</span>[<span class="ruby-string">'tag'</span>]=(<span class="ruby-identifier">e</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>])

        <span class="ruby-ivar">@sort</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
          <span class="ruby-keyword">if</span>
          <span class="ruby-identifier">e</span>[<span class="ruby-value">0</span>]<span class="ruby-operator">==</span><span class="ruby-identifier">marker</span>
            <span class="ruby-identifier">datafield</span> <span class="ruby-string">&quot;            subfield['code']=e[1][0]
            subfield.content=e[1][1..-1]
          end}
      end}

    #dub&lt;&lt; e.tag.to_s.sub(/\$.*/,&quot;&quot;)+e.position.to_s
    #@build.insertSubelement(e.tag, e.content)
    #end

    #@rec.each { |e|
    #if !dub.include?(e.tag.to_s.sub(/\$.*/,&quot;&quot;)+e.position.to_s)
    #@build.insertElement(e.tag, e.content)

    #dub&lt;&lt; e.tag.to_s.sub(/\$.*/,&quot;&quot;)+e.position.to_s
    #@build.insertSubelement(e.tag, e.content)
    #end
    #           }

    #@build.insertElement('001', '4711')
    #@build.insertElement('100$a', 'Brahms')

  end

  def convert
    rismid=&quot;458002040&quot;
    dn ='dn:http://www.loc.gov/MARC21/slim'
    xml_document = LibXML::XML::Document.file('/home/stephan/RSQV/cz.xml')
    if params[&quot;extext&quot;]
      rismid=params[&quot;extext&quot;][&quot;name&quot;]
    end
    book_xpath = '//dn:record/dn:controlfield[@tag=&quot;001&quot;][contains(.,&quot;'+rismid+'&quot;)]/..'
    nodes=xml_document.find(book_xpath,dn)
    @ids=xml_document.find('//dn:record/dn:controlfield[@tag=&quot;001&quot;]/text()',dn).to_a.shuffle[0..6]
    @archive_node=Array.new
    nodes.each { |e|  @archive_node.push(e.copy(:deep =&gt; false))}
    doc = LibXML::XML::Document.new()
    @doc1=doc
    doc.root = LibXML::XML::Node.new(&quot;collection&quot;)
    #XML::Namespace.new(doc.root, nil, 'http://www.loc.gov/MARC21/slim')

    if nodes.size &gt;= 1
      nodes.each { |item|
        doc.root &lt;&lt; record=LibXML::XML::Node.new(&quot;record&quot;)
        item.find('dn:leader',dn).each {|e| record&lt;&lt;leader=LibXML::XML::Node.new(&quot;leader&quot;) ;  leader.content=e.content }
        item.find('dn:controlfield[@tag=&quot;001&quot;]',dn).each {|e|  insert_controlfield(record, '001', e.content)}
        item.find('dn:controlfield[@tag=&quot;003&quot;]',dn).each {|e|  insert_controlfield(record, '003', e.content)}
        item.find('dn:controlfield[@tag=&quot;005&quot;]',dn).each {|e|  insert_controlfield(record, '005', e.content)}
        item.find('dn:controlfield[@tag=&quot;007&quot;]',dn).each {|e|  insert_controlfield(record, '007', e.content)}
        item.find('dn:controlfield[@tag=&quot;008&quot;]',dn).each {|e|  insert_controlfield(record, '008', e.content)}

    
        data={
          '001'=&gt;nil,
          '003'=&gt;nil,
          '005'=&gt;nil,
          '007'=&gt;nil,
          '008'=&gt;nil,
          '028'=&gt;%w[ a d ],
          '031'=&gt;%w[ a b c m g n o p r ],
          '041'=&gt;%w[ a ],
          '047'=&gt;%w[ a ],
          '048'=&gt;%w[ a ],
          '072'=&gt;%w[ a x ],
          '080'=&gt;%w[ 2 a ],
          '100'=&gt;%w[ a d ],
          '240'=&gt;%w[ a m n r ],
          '245'=&gt;%w[ a b c h n p ],
          '246'=&gt;%w[ a ],
          '250'=&gt;%w[ a ],
          '260'=&gt;%w[ a b c ],
          '300'=&gt;%w[ a c e ],
          '500'=&gt;%w[ a ],
          '501'=&gt;%w[ a ],
          '505'=&gt;%w[ a r t ],
          '518'=&gt;%w[ a ],
          '561'=&gt;%w[ a ],
          '567'=&gt;%w[ a ],
          '650'=&gt;%w[ a ],
          '653'=&gt;%w[ a ],
          '655'=&gt;%w[ a ],
          '700'=&gt;%w[ 4 a d ],
          '740'=&gt;%w[ a ],
          '856'=&gt;%w[ 3 u ],
          '910'=&gt;%w[ a b ],
        }
    
        taglist=['leader']
        y=data.keys.sort.each{|k|
          if data[k]
            data[k].sort.each{|v|
              taglist&lt;&lt;k+'$'+v     }
          else
            taglist&lt;&lt;k
          end  }

          
        data={
          #'020'=&gt;%w[ a c ],
          '028'=&gt;%w[ a d ],
          '031'=&gt;%w[ a b c m g n o p r 2 ],
          #'040'=&gt;%w[ a b c ],
          '041'=&gt;%w[ a ],
          '047'=&gt;%w[ a ],
          '048'=&gt;%w[ a ],
          #'072'=&gt;%w[ 2 9 a x ],
          '072'=&gt;%w[ a x ],
          '500&lt;-080'=&gt;%w[ 2 a ],
          #'100'=&gt;%w[ 4 7 a c d ],
          '100'=&gt;%w[ 4 a d ],
          #'240'=&gt;%w[ a m n p r ],
          '240'=&gt;%w[ a m n r ],
          '245'=&gt;%w[ a b c h n p ],
          '730&lt;-246'=&gt;%w[ a ],
          '250'=&gt;%w[ a ],
          #'254'=&gt;%w[ a ],
          '260'=&gt;%w[ a b c ],
          #'300'=&gt;%w[ a b c e ],
          '300'=&gt;%w[ a c e ],
          #'306'=&gt;%w[ a ],
          #'490'=&gt;%w[ a ],
          '500'=&gt;%w[ a ],
          '501'=&gt;%w[ a ],
          '505'=&gt;%w[ a r t ],
          '518'=&gt;%w[ a ],
          #'546'=&gt;%w[ a ],
          '561'=&gt;%w[ a ],
          #'563'=&gt;%w[ a ],
          '567'=&gt;%w[ a ],
          #'568'=&gt;%w[ a ],
          #'580'=&gt;%w[ a ],
          #'600'=&gt;%w[ 2 a ],
          #'610'=&gt;%w[ 2 7 a ],
          #'648'=&gt;%w[ 2 a ],
          #'650'=&gt;%w[ 2 a y z ],
          '650'=&gt;%w[ a ],
          '653'=&gt;%w[ a ],
          #---&gt; AH600T
          #'655'=&gt;%w[ 2 a ],
          '655'=&gt;%w[ a ],
          #'700'=&gt;%w[ 3 4 7 a c d l o p t ],
          '700'=&gt;%w[ 4 a d ],
          '730&lt;-740'=&gt;%w[ a ],
          #'772'=&gt;%w[ t ],
          #'830'=&gt;%w[ a ],
          '856'=&gt;%w[ 3 u ],
          '852&lt;-910'=&gt;%w[ a b ],
          #'964'=&gt;%w[ a x z ],
        }

        data.keys.sort.each {|k|
          tag=k.sub(/.*&lt;-/,&quot;&quot;)
          codes=data[k]

          if k=='240'
            items=item.find('dn:datafield[@tag=&quot;'+tag+'&quot;]',dn)
            if items.size!=0
              items.each { |e|
                df=insert_datafield(record, tag)
                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    if %w[ a ].include?(code)
                      insert_subfield(df,code, e.content[0..-2])
                    else
                      insert_subfield(df,code, e.content)
                    end}
                }
              }

            else
              df=insert_datafield(record,'240')
              insert_subfield(df, 'a', 'Pieces')
            end

          else
            item.find('dn:datafield[@tag=&quot;'+tag+'&quot;]',dn).each { |e|

              if tag=='031'
                df=insert_datafield(record, tag)
                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    if %w[ a b c].include?(code)
                      insert_subfield(df,code, e.content.sub(/\A0/,&quot;&quot;))
                    else
                      insert_subfield(df,code, e.content)
                    end}}

              elsif tag=='080'
                df=insert_datafield(record, '500')
                term=[]
                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    term&lt;&lt;e.content    }                                        }
                insert_subfield(df,'a', term.join(&quot; &quot;))

              elsif tag=='100'
                df=insert_datafield(record, tag)
                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    if %w[ a ].include?(code)
                      insert_subfield(df,code, e.content[0..-2])
                    else
                      insert_subfield(df,code, e.content)
                    end}}

              elsif tag=='245'
                df=insert_datafield(record, tag)
                title=[]
                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    if %w[ a b c h n p ].include?(code)
                      title&lt;&lt; e.content
                    else
                      insert_subfield(df,code, e.content)
                    end}
                }
                if title.size &gt;0
                  insert_subfield(df,'a', title.join(&quot; /  &quot;))
                end

              elsif tag=='246'
                df=insert_datafield(record, '730')

                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    insert_subfield(df,code, e.content)   }
                }

              elsif tag=='653'
                df=insert_datafield(record, '650')

                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    insert_subfield(df,code, e.content)   }
                }

              elsif tag=='700'
                df=insert_datafield(record, tag)
                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                    if %w[ a ].include?(code)
                      insert_subfield(df,code, e.content[0..-2])
                    else
                      insert_subfield(df,code, e.content)
                    end}}

              elsif tag=='910'
                df=insert_datafield(record, '852')
                codes.each {|code|
                  if code=='a'
                    bib=e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn)
                    if bib.size!=0
                      b.each {|e|
                        insert_subfield(df,code, e.content)
                      }
                    else
                      insert_subfield(df,code, 'CZ-Bu')
                    end
                  else
                    e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e|
                      insert_subfield(df,code, e.content)}
                  end
                }

              else
                df=insert_datafield(record, tag)
                codes.each {|code| e.find('dn:subfield[@code=&quot;'+code+'&quot;]',dn).each {|e| insert_subfield(df,code, e.content)} }
              end
            }  end
        }

      }
    else
      @node=&quot;No result&quot;
    end

  end
end

&quot;</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'subfield'</span>)
</pre>
          </div><!-- ooldconvert-source -->
          
        </div>

        

        
      </div><!-- ooldconvert-method -->

    
      <div id="method-i-showsubfield" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">showsubfield</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="showsubfield-source">
            <pre><span class="ruby-comment"># File app/controllers/cz_controller.rb, line 58</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">showsubfield</span>
  <span class="ruby-comment">#@tag='1111'</span>
  <span class="ruby-comment">#@code='1111'</span>

  <span class="ruby-comment">#@subfield=&quot;&quot;</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:subfield</span>]
    <span class="ruby-ivar">@subfield</span>=<span class="ruby-identifier">params</span>[<span class="ruby-value">:subfield</span>]
    <span class="ruby-ivar">@tag</span>=<span class="ruby-ivar">@subfield</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'$'</span>)[<span class="ruby-value">0</span>]
    <span class="ruby-ivar">@code</span>=<span class="ruby-ivar">@subfield</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'$'</span>)[<span class="ruby-value">1</span>]
    <span class="ruby-identifier">dn</span> =<span class="ruby-string">'dn:http://www.loc.gov/MARC21/slim'</span>
    <span class="ruby-identifier">xml_document</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">file</span>(<span class="ruby-string">'/home/stephan/RSQV/cz.xml'</span>)
    <span class="ruby-identifier">book_xpath</span> = <span class="ruby-string">'//dn:record/dn:datafield[@tag=&quot;'</span><span class="ruby-operator">+</span><span class="ruby-constant">String</span>(<span class="ruby-ivar">@tag</span>)<span class="ruby-operator">+</span><span class="ruby-string">'&quot;]/dn:subfield[@code=&quot;'</span><span class="ruby-operator">+</span><span class="ruby-constant">String</span>(<span class="ruby-ivar">@code</span>)<span class="ruby-operator">+</span><span class="ruby-string">'&quot;]'</span>
    <span class="ruby-ivar">@nodes</span>=<span class="ruby-identifier">xml_document</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">book_xpath</span>,<span class="ruby-identifier">dn</span>)
    <span class="ruby-ivar">@countno</span>=<span class="ruby-ivar">@nodes</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- showsubfield-source -->
          
        </div>

        

        
      </div><!-- showsubfield-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

